/*
 * FileName:       main.h
 * Author:         Kingsea  Version: v1.0  Date: 2019-5-17
 * Description:    
 * History:        
 *     <author>   	<version>    	<time>    	<desc>
 *     Kingsea   	v1.0    	2019-5-17    
 */

#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include "nordic_common.h"
#include "nrf.h"

#include "fds.h"
#include "nrf_drv_clock.h"
#include "nrf_ble_gatt.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_drv_wdt.h"
#include "nrf_drv_pwm.h"

#include "ble.h"
#include "ble_hci.h"
#include "ble_srv_common.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_db_discovery.h"
#include "ble_conn_params.h"
#include "ble_conn_state.h"
#include "nrf_sdh.h"
#include "nrf_sdh_soc.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "ble_nus_c.h"

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#include "bsp.h"
#include "bsp_btn_ble.h"
#include "peer_manager.h"
#include "app_error.h"
#include "app_timer.h"
#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif

#ifndef MAIN_H__
#define MAIN_H__
#ifdef __cplusplus
extern "C"{
#endif 

// software main version
#define SW_MAIN_VERSION_S               	"10" // Vx.x string

#define BLE_GAP_PHY_2MBPS_EN 				(1)
#define HW_UART_BAUDRATE_SET				(NRF_UART_BAUDRATE_115200) // (NRF_UART_BAUDRATE_460800) // 

#define DEVICE_NAME                         "PlaymateAir"                            /**< Name of device. Will be included in the advertising data. */
#define MANUFACTURER_NAME                   "NordicSemiconductor"                   /**< Manufacturer. Will be passed to Device Information Service. */

#define APP_BLE_OBSERVER_PRIO               3                                       /**< Application's BLE observer priority. You shouldn't need to modify this value. */
#define APP_BLE_CONN_CFG_TAG                1                                       /**< A tag identifying the SoftDevice BLE configuration. */

#define BATTERY_LEVEL_MEAS_INTERVAL         APP_TIMER_TICKS(2000)                   /**< Battery level measurement interval (ticks). */
#define MIN_BATTERY_LEVEL                   81                                      /**< Minimum simulated battery level. */
#define MAX_BATTERY_LEVEL                   100                                     /**< Maximum simulated 7battery level. */
#define BATTERY_LEVEL_INCREMENT             1                                       /**< Increment between each simulated battery level measurement. */

#define DEAD_BEEF                           0xDEADBEEF                              /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */

#define OSTIMER_WAIT_FOR_QUEUE              2                                       /**< Number of ticks to wait for the timer queue to be ready */

#define APP_FEATURE_NOT_SUPPORTED           (BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2)  /**< Reply when unsupported features are requested. */

////////////////////////////////////////////
#define UART_TX_BUF_SIZE        1024                                    /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE        1024                                    /**< UART RX buffer size. */

#define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN              /**< UUID type for the Nordic UART Service (vendor specific). */

#define SCAN_INTERVAL           0x00A0                                  /**< Determines scan interval in units of 0.625 millisecond. */
#define SCAN_WINDOW             0x0050                                  /**< Determines scan window in units of 0.625 millisecond. */
#define SCAN_TIMEOUT            0x0000                                  /**< Timout when scanning. 0x0000 disables timeout. */

#define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS)        /**< Determines minimum connection interval in millisecond. */
#define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS(150, UNIT_1_25_MS)        /**< Determines maximum connection interval in millisecond. */
#define SLAVE_LATENCY           0                                       /**< Determines slave latency in counts of connection events. */
#define SUPERVISION_TIMEOUT     MSEC_TO_UNITS(4000, UNIT_10_MS)         /**< Determines supervision time-out in units of 10 millisecond. */

#define UUID16_SIZE             2                                       /**< Size of 16 bit UUID */
#define UUID32_SIZE             4                                       /**< Size of 32 bit UUID */
#define UUID128_SIZE            16                                      /**< Size of 128 bit UUID */


#define appuart_printf(...) 	printf(__VA_ARGS__)
//#define appuart_printf(...)
//////////////////////////////////////////////////////////////////////////
ble_nus_c_t * get_nus_c_object(void);
uint16_t get_ble_nus_max_data_len(void);

#ifdef __cplusplus
}
#endif 
#endif /* MAIN_H__ */ 

